package com.xiemu.ironman.core.utils;


public class ApiResult<T> {
    private int code;
    private String message;
    private boolean success;
    private T data;

    public ApiResult() {}

    public ApiResult(T data) {
        this.code = 200;
        this.message = "success";
        this.success = true;
        this.data = data;
    }

    public ApiResult(int code, String message, boolean success, T data) {
        this.code = code;
        this.message = message;
        this.success = success;
        this.data = data;
    }

    public ApiResult(int code, String message, T data) {
        this.code = code;
        this.message = message;
        this.data = data;
    }

    public static <T> ApiResult<T> fail() {
        ApiResult<T> r = new ApiResult<>();
        r.setSuccess(false);
        r.setCode(401);
        r.setMessage("fail");
        return r;
    }

    public ApiResult code(Integer code) {
        this.setCode(code);
        return this;
    }

    public ApiResult message(String message) {
        this.setMessage(message);
        return this;
    }

    public static <T> ApiResult<T> defSuccess(T data) {
        ApiResult<T> apiResult = new ApiResult<T>(data);
        return apiResult;
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public boolean isSuccess() {
        return success;
    }

    public void setSuccess(boolean success) {
        this.success = success;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }
}
